#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <string.h>

void string_break(char *str, char dst[5][128])
{
	if (str == NULL || dst == NULL) {
		return;
	}

	char *pos_begin = str;
	char *pos_end = str;
	int len = 0;
	
	pos_end = strstr(pos_begin, ",");
	len = pos_end - pos_begin;
	strncpy(dst[0], pos_begin, len);
	dst[0][len] = '\0';
	pos_begin = pos_begin + len + 1;

	pos_end = strstr(pos_begin, ",");
	len = pos_end - pos_begin;
	strncpy(dst[1], pos_begin, len);
	dst[1][len] = '\0';
	pos_begin = pos_begin + len + 1;

	pos_end = strstr(pos_begin, ",");
	len = pos_end - pos_begin;
	strncpy(dst[2], pos_begin, len);
	dst[2][len] = '\0';
	pos_begin = pos_begin + len + 1;

	pos_end = strstr(pos_begin, ",");
	len = pos_end - pos_begin;
	strncpy(dst[3], pos_begin, len);
	dst[3][len] = '\0';
	pos_begin = pos_begin + len + 1;

	strcpy(dst[4], pos_begin);
}

int main()
{
	char test[5][128];
	char str[512] = "mysql,sklccdpi,sklccroot,sklccroot,192.168.139.102";
	string_break(str, test);

	int i = 0;
	for ( ; i < 5; i++) {
		printf("%s\n", test[i]);
	}
}
